<!--
Copyright © 2017, Che-Wei Hsu <cwxhsu@gmail.com>
This file is part of the MintCM.
Some rights reserved. See README.
-->

<html>

<head>

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="jquery_main.js"></script>
<script type="text/javascript" src="json3.js"></script>
<script type="text/javascript" src="mcm_jslib_api.js"></script>
<script type="text/javascript" src="mcm_jslib_data_info_auto.js"></script>
<link rel="stylesheet" href="web_app_0304_style.css">

<script type="text/javascript">
function body_init()
{
    var self_jslib, req_cmd = "", rep_ret, mcm_dv;


    // 指定要讀出的資料.
    req_cmd = "&get.device" +
              "&get.device.system";

    // 送出讀出資料請求.
    self_jslib = new mcm_jslib_lib_t();
    self_jslib.socket_path = "@mintcm";
    self_jslib.session_permission = mcm_session_permission.ro;
    self_jslib.session_stack_size = 0;
    self_jslib.request_command = req_cmd;
    self_jslib.data_format = mcm_data_format.all_default;
    self_jslib.other_query = "";
    rep_ret = mcm_jslib_obtain_config(self_jslib);
    if(rep_ret.rep_code < mcm_return_code.pass)
    {
        alert("call mcm_jslib_obtain_config() fail" +
              "[" + rep_ret.rep_code + "]");
        mcm_jslib_run_script(rep_ret.rep_data);
        return;
    }
    // 處理資料格式.
    mcm_dv = JSON.parse(rep_ret.rep_data);

    // 顯示 device
    $("#descript_text").val(mcm_dv.device.descript);
    $("#serial_number_text").val(mcm_dv.device.serial_number);

    // 顯示 device.system
    $("#date_text").val(mcm_dv.device.system.date);
    $("#ip_addr_text").val(mcm_dv.device.system.ip_addr);
    $("#uptime_text").val(mcm_dv.device.system.uptime);
    $("#loading_text").val(mcm_dv.device.system.loading);
}

// 設定資料.
function config_set()
{
    var self_jslib, req_cmd = "", rep_ret;


    // 設定 device
    req_cmd += "&set.device.descript=" +
               mcm_jslib_convert_submit_str($("#descript_text").val());
    req_cmd += "&set.device.serial_number=" +
               $("#serial_number_text").val();

    // 設定 device.system
    req_cmd += "&set.device.system.date=" +
               mcm_jslib_convert_submit_str($("#date_text").val());
    req_cmd += "&set.device.system.ip_addr=" +
               mcm_jslib_convert_submit_str($("#ip_addr_text").val());
    req_cmd += "&set.device.system.uptime=" +
               $("#uptime_text").val();
    req_cmd += "&set.device.system.loading=" +
               $("#loading_text").val();

    // 送出修改資料請求.
    self_jslib = new mcm_jslib_lib_t();
    self_jslib.socket_path = "@mintcm";
    self_jslib.session_permission = mcm_session_permission.rw;
    self_jslib.session_stack_size = 0;
    self_jslib.request_command = req_cmd;
    self_jslib.after_complete = mcm_after_complete.reload;
    self_jslib.other_query = "";
    rep_ret = mcm_jslib_submit_config(self_jslib);
    if(rep_ret.rep_code < mcm_return_code.pass)
    {
        alert("call mcm_jslib_submit_config() fail" +
              "[" + rep_ret.rep_code + "]");
        mcm_jslib_run_script(rep_ret.rep_data);
        return;
    }
    mcm_jslib_run_script(rep_ret.rep_data);
}
</script>

</head>

<body onload="body_init()">

  <div>[set]</div>

  <table class="css_table1">
    <tr>
      <td class="css_td1">device.descript</td>
      <td class="css_td1">
        <input id="descript_text" type="text" size="32">
      </td>
    </tr>
    <tr>
      <td class="css_td1">device.serial_number</td>
      <td class="css_td1">
        <input id="serial_number_text" type="text" size="32">
      </td>
    </tr>
  </table>

  <table class="css_table1">
    <tr>
      <td class="css_td1">device.system.date</td>
      <td class="css_td1">
        <input id="date_text" type="text" size="32">
      </td>
    </tr>
    <tr>
      <td class="css_td1">device.system.ip_addr</td>
      <td class="css_td1">
        <input id="ip_addr_text" type="text" size="32">
      </td>
    </tr>
    <tr>
      <td class="css_td1">device.system.uptime</td>
      <td class="css_td1">
        <input id="uptime_text" type="text" size="32">
      </td>
    </tr>
    <tr>
      <td class="css_td1">device.system.loading</td>
      <td class="css_td1">
        <input id="loading_text" type="text" size="32">
      </td>
    </tr>
  </table>

  <button type="button" onclick="config_set()">set</button>

</body>

</html>
